package tp_lab1_liczba;

import static org.junit.Assert.*;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

public class LiczbaTest4 {
	private static Liczba liczba;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		liczba = new Liczba();
	}

	@Test
	public void ShouldThrowFailIfThirdBaseGoingBad() {
		liczba.setDec(17);
		try {
			assertEquals(liczba.convertFromDec(3), "122");
		} catch (WrongNumberException e) {
			fail("WrongNumberException should not occure, but it did");
		}
	}

	@Ignore
	@Test
	public void ShouldThrowFailIfHexGoingBad() {
		liczba.setDec(10);
		try {
			assertEquals(liczba.convertFromDec(16), "A");
		} catch (WrongNumberException e) {
			fail("WrongNumberException should not occure, but it did");
		}
	}

	@Test(expected = WrongNumberException.class)
	public void testShouldThrowExceptionWhenDecIsNegative()
			throws WrongNumberException {
		liczba.setDec(-17);
		liczba.convertFromDec(3);
	}

	@Test(expected = WrongNumberException.class)
	public void ShouldThrowExceptionWhenBaseIsLowerThanBinary()
			throws WrongNumberException {
		liczba.setDec(12);
		liczba.convertFromDec(1);
	}

	@Test(expected = WrongNumberException.class)
	public void ShouldThrowExceptionWhenBaseIsHigherThanHex()
			throws WrongNumberException {
		liczba.setDec(12);
		liczba.convertFromDec(17);
	}

	@Test(timeout = 80)
	public void ShouldThrowFailWhenTimeIsAboveEightySec() {
		liczba.setDec(45);
		try {
			liczba.convertFromDec(4);
		} catch (WrongNumberException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/** Some test from Aleks */
	@Test
	public void testNrOne() throws WrongNumberException {
		liczba.setDec(10);
		assertEquals("1010", liczba.convertFromDec(2));
	}

	@AfterClass
	public static void tearDownAfterClass() {
		liczba = null;
	}
}
